package com.yq.homework.day21;

/**
 * @author 3307235355@qq.com
 * @since 2022/06/22 15:34
 * 举例： 在字符串”woaijavawozhenaijavawozhendeaijavawozhendehenaijavaxinbuxinwoaijavagun”
 * 中java出现了5次 提
 * 示：可以考虑使用indexOf方法，
 * 仅考虑本题举出的字符串，
 * 无需复杂考虑
 */
public class Demo03 {
    public static void main(String[] args) {
        String s = "woaijavawozhenaijavawozhendeaijavawozhendehenaijavaxinbuxinwoaijavagun";
        int i = 0;
        int count = 0;
        for (int j = 0; j < s.length(); j++) {
            i = s.indexOf("java");
            s = s.substring(i+4);
            if (i<0){
                break;
            }
            count++;
        }
        System.out.println("java一共出现了："+count);
    }
}
